package com.deYang.app.ljodfh.ui.activities;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.deYang.app.ljodfh.R;
import com.deYang.app.ljodfh.base.BaseActivity;
import com.deYang.app.ljodfh.ui.utils.TitleUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

public class H5Activity extends BaseActivity {
    @BindView(R.id.webView_h5)
    protected WebView webView;
    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new TitleUtils(this);
        initView();
    }

    @Override
    protected void initInject() {
        setContentView(R.layout.activity_h5);
        ButterKnife.bind(this);
    }

    private void initView() {
        WebSettings settings = webView.getSettings();
        // 使用缓存
        settings.setCacheMode(WebSettings.LOAD_DEFAULT);
        //使h5页面适应手机屏幕
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        //设置可以支持缩放
        settings.setSupportZoom(true);
        //设置出现缩放工具
        settings.setBuiltInZoomControls(true);
        //隐藏缩放工具
        settings.setDisplayZoomControls(false);
        //扩大比例的缩放
        settings.setUseWideViewPort(true);
        // 支持JavaScript
        settings.setJavaScriptEnabled(true);
//        settings.setMediaPlaybackRequiresUserGesture(false);
        webView.setWebChromeClient(new WebChromeClient());
        webView.setWebViewClient(new WebViewClient());
        Intent intent = getIntent();
        if (intent != null) {
            url = intent.getStringExtra(EX_HTML);
            if (!TextUtils.isEmpty(url)) {
                webView.loadUrl(url);
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (webView != null) {
            webView.removeAllViews();
            webView.destroy();
        }
    }
}
